package com.youi.shop.controller;


import com.youi.shop.commons.result.RespEntity;
import com.youi.shop.pojo.qo.order.OrderCreateQO;
import com.youi.shop.pojo.vo.order.OrderVO;
import com.youi.shop.service.OrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author xxf
 * @since 2020-11-09
 */
@RestController
@RequestMapping("/order")
@Api(tags = "订单业务接口")
public class OrderController {

    @Resource
    OrderService orderService;


    /**
     * 创建订单
     * @param orderCreateQO
     * @return
     */
    @ApiOperation("创建订单")
    @PostMapping("/createOrder")
    public RespEntity<OrderVO> createOrder(@ApiParam("订单创建对象") @RequestBody OrderCreateQO orderCreateQO) {

        OrderVO orderVO =orderService.createOrder(orderCreateQO);
        return RespEntity.success(orderVO);
    }

    /**
     * 根据会员id查询订单
     * @param memberId
     * @return
     */
    @ApiOperation("查询会员的所有订单")
    @GetMapping("/findOrderByMemberId/{memberId}")
    public RespEntity<List<OrderVO>> findOrderByMemberId(@PathVariable Long memberId) {
        List<OrderVO> list = orderService.selectByMemberId(memberId);

        return RespEntity.success(list);
    }

    /**
     * 根据订单id查询一张订单
     * @param orderId
     * @return
     */
    @ApiOperation("查询单条订单")
    @GetMapping("/findOrderByOrderId/{orderId}")
    public RespEntity<OrderVO> findOrderByOrderId(@PathVariable Long orderId) {
        OrderVO orderVO = orderService.selectByOrderId(orderId);

        return RespEntity.success(orderVO);
    }

    /**
     * 支付订单
     * @param orderId
     * @return
     */
//    @ApiOperation("支付订单")
//    @GetMapping("/")
//    public RespEntity<OrderVO> pay(@PathVariable Long orderId) {
//        OrderVO orderVO = orderService.selectByOrderId(orderId);
//
//        return RespEntity.success(orderVO);
//    }













}
